<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="css/css.css" rel="stylesheet" type="text/css" />
<link href="css/common.css" rel="stylesheet" type="text/css" />
<link href="css/font-awesome.min.css" rel="stylesheet" type="text/css" />
<script src="js/jquery.min.1.8.2.js" type="text/javascript"></script>
<script src="js/jquery.SuperSlide.2.1.1.js" type="text/javascript"></script>
<script type="text/javascript" src="js/slide.js"></script>
<script src="js/common_js.js" type="text/javascript"></script>
<script src="js/jquery.foucs.js" type="text/javascript"></script>
<script type="text/javascript" src="js/axios.min.js"></script>
<title>用户注册</title>
</head>

<body>
<!--顶部样式-->
<div class="top_header">
<em class="left_img"></em>
<div class="header clearfix" id="header">
<div class="header_Section">
 <script>$("#Navigation").slide({titCell:".Navigation_name li"});</script>
</div>
</div>
<em class="right_img"></em>
</div>
<!---->
<div><a href="#"><img src="images/AD_page_img_02.png" width="100%"/></a></div>
<!--注册样式-->
<div class="Inside_pages clearfix">
    <div class="register">
        <div class="register_style">
            <div class="u_register">
                <ul>
                    <li><label class="name">手机号码：</label><input name="phone" type="text" class="text_Add"/></li>
                    <li><label class="name">用户名称：</label><input name="consumerName" type="text" class="text_Add"/></li>
                    <li><label class="name">设置密码：</label><input name="password" type="password" class="text_Add" placeholder="6-20个字符，由字母、数字和符号的两种以上组合"/></li>
                    <li><label class="name">确认密码：</label><input name="repassword" type="password" class="text_Add"/></li>
                </ul>
                <div class="auto-register">
                    <label class="auto-label">
                        <input type="checkbox" id="rememberMe">
                        <span><a href="#">《鲜果售卖网站注册协议》</a></span>
                    </label>
                </div>
                <div class="register-btn">
                    <button class="btn_register" onclick="regist()">注&nbsp;&nbsp;&nbsp;&nbsp;册</button>
                </div>
            </div>
			<div class="login_link"><a href="login.html">已有账号，去登录</a></div>
        </div>
    </div>
</div>
</body>
<script>
	 const getFormData = () => {
	         return {
	             phone: document.getElementsByName("phone")[0].value,
	             consumerName: document.getElementsByName("consumerName")[0].value,
	             password: document.getElementsByName("password")[0].value,
	             repassword: document.getElementsByName("repassword")[0].value // 添加确认密码的获取
				 
	         };
	     };
	 
	     const regist = () => {
			 
	         // 获取表单数据
	         const formData = getFormData();
	         // 确认密码是否一致等基本验证逻辑可以在这里添加
	         if(formData.password !== formData.repassword) {
	             alert("两次输入的密码不一致！");
	             return;
	         }
			 // 获取复选框元素
			 var rememberMeCheckbox = document.getElementById('rememberMe');
					  
			 // 检查复选框是否被选中
			 if (!rememberMeCheckbox.checked) {
				 alert('请先阅读并勾选同意《国际商贸城网站注册协议》');
				 return; // 阻止注册操作继续
			 }
	         // 发送注册请求
	         axios.post("http://127.0.0.1:8080/consumer/register", formData)
	             .then((response) => {
	                 console.log(response);
						if(response.data.success){
							sessionStorage.setItem('phone',response.data.phone);
							window.location.href="index.html"
						}else{
							alert(response.data.message)
						}
	             })
	             .catch((error) => {
	                 console.error("注册失败:", error);
	                 // 处理错误情况
	             });
	     };
</script>
</html>
